//
//  OO_AddressTableViewCell.m
//  ShopProject
//
//  Created by macbookpro on 2018/9/29.
//  Copyright © 2018年 ShopProject. All rights reserved.
//

#import "OO_AddressTableViewCell.h"
static NSString *const PingFangSCMedium = @"PingFang-SC-Medium";
static NSString *const PingFangSCNormal = @"PingFang SC";
@implementation OO_AddressTableViewCell
{
    
    UILabel *_nameLable;/*收货人*/
    UILabel *_phoneLable;/*电话*/
    UILabel *_addressLable;/*地址*/
    UIButton *_eidtButton;/*编辑*/
        UIView *_buttomView;/*底部灰色线条*/
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = 0;
        [self setupUI];
        
    }
    return self;
    
    
}

- (void)awakeFromNib {
    [super awakeFromNib];

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

-(void)setupUI{
    
    UILabel *nameLable = [UILabel new];
    nameLable.text = @"name";
    nameLable.backgroundColor = [UIColor clearColor];
    nameLable.textAlignment = NSTextAlignmentLeft;
    nameLable.textColor = [UIColor blackColor];
    nameLable.font = [UIFont fontWithName:PingFangSCMedium size:14.0f];
    [self.contentView addSubview:nameLable];
    _nameLable = nameLable;
    
    
    UILabel *phoneLable = [UILabel new];
    phoneLable.text = @"12111122211";
    phoneLable.textAlignment  = NSTextAlignmentLeft;
    phoneLable.font = [UIFont fontWithName:PingFangSCNormal size:14.0f];
    phoneLable.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:phoneLable];

    _phoneLable = phoneLable;
    
    
    UILabel *addressLable = [UILabel new];
    addressLable.text = @"adressADSASDAsdknakSHDKAhslkdnb,SNDB,kjsabd m,hklasnMBDHKLBMNbjhklbnmbhlijdbbjahkslnbdhkljas,nmdbj,hklfbabjhkls,fbjhkla,smndhflhb,mnahluskjhdmnvfhlasmdjhklfbvaskldbfahbdfkjhalkdhfkahsdfhubjhabfjliasbvfhwjqrialsdbfhjisalkbdfhjlasfkdbnrwjhkflasbrwjhasvbafhalsjbfrbjhasfjbqrbwjhasbf";
    addressLable.font = [UIFont fontWithName:PingFangSCNormal size:14.0f];
    addressLable.textColor = [UIColor lightGrayColor];
    addressLable.numberOfLines  = 0;
    [self.contentView addSubview:addressLable];
    _addressLable = addressLable;
    
    
    
    UIButton *editButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [editButton setImage:[UIImage imageNamed:@"edit"] forState:0];
    [editButton addTarget:self action:@selector(editButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:editButton];
    _eidtButton = editButton;
   
    UIView *buttomView = [UIView new];
    buttomView.backgroundColor = RGB(240, 240, 240,1);
    [self.contentView addSubview:buttomView];
    _buttomView = buttomView;
    
    
    [self setupConstraints];
    
}
-(void)setupConstraints{
    
    UIView *subView = self.contentView;
    CGFloat margin = 8.0f;
    _nameLable.sd_layout
    .topSpaceToView(subView, margin)
    .leftSpaceToView(subView, margin)
    .rightSpaceToView(subView, 60)
    .heightIs(20.0f);
    
    _phoneLable.sd_layout
    .topSpaceToView(_nameLable, margin)
    .leftSpaceToView(subView, margin)
    .rightSpaceToView(subView, 60)
    .heightIs(20.0f);
    
    
    _addressLable.sd_layout
    .topSpaceToView(_phoneLable, margin)
    .leftSpaceToView(subView, margin)
    .rightSpaceToView(subView, margin)
    .autoHeightRatio(0);
    
    _buttomView.sd_layout
    .topSpaceToView(_addressLable, 8.0f)
    .leftEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .heightIs(0.5f);
    
    _eidtButton.sd_layout
    .topSpaceToView(subView, margin)
    .rightSpaceToView(subView, 0)
    .leftSpaceToView(_nameLable, 0)
    .heightIs(8+8+20+20);
    
    
    [self setupAutoHeightWithBottomView:_buttomView bottomMargin:0];
    
    
}

-(void)setModel:(OO_AddressModel *)model{
    
    _model  = model;
    _nameLable.text = model.peopleName;
    _phoneLable.text = model.phone;
    _addressLable.text = [NSString stringWithFormat:@"%@%@",model.city,model.adress];
    [self setupAutoHeightWithBottomView:_buttomView bottomMargin:0];
}
-(void)editButtonClicked{
    
    
    if ([self.delgate respondsToSelector:@selector(editButtonClickedAtCell:)]) {
        [self.delgate editButtonClickedAtCell:self];
    }
    
}
@end
